home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_u_z / vlistsam.zip / VLSCROLL.C < prev    next >
C/C++ Source or Header  |  1992-09-27  |  22KB  |  641 lines

  1. #include "vlistint.h"
  2.  
  3. #include <string.h>
  4.  
  5. static void SetFocustoLB(PVLBOX pVLBox);
  6. static void SetFocustoVLB(PVLBOX pVLBox);
  7.  
  8. int VLBScrollDownLine( PVLBOX pVLBox)
  9. {
  10.     RECT   UpdRect;
  11.     int    nSelected;
  12.  
  13.     if ( pVLBox->wFlags & USEDATAVALUES )
  14.         pVLBox->vlbStruct.lIndex = -1L;
  15.     else
  16.         pVLBox->vlbStruct.lIndex = pVLBox->lToplIndex + pVLBox->nLines - 1L;
  17.  
  18.     pVLBox->vlbStruct.lpTextPointer = NULL;
  19.     pVLBox->vlbStruct.lData = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, pVLBox->nCountInBox-1, 0L);
  20.     SendMessage(pVLBox->hwndParent, VLB_NEXT, 0, (LPARAM)((LPVLBSTRUCT)&(pVLBox->vlbStruct)));
  21.     if ( pVLBox->vlbStruct.nStatus == VLB_OK ) {
  22.        nSelected = (int)SendMessage(pVLBox->hwndList, LB_GETCURSEL, 0, 0L);
  23.        if ( nSelected == 0 ) {
  24.            SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WORD)-1, 0L);
  25.            SetFocustoVLB(pVLBox);
  26.        }
  27.  
  28.        //
  29.        // Remove the top String
  30.        //
  31.        SendMessage(pVLBox->hwndList, LB_DELETESTRING, 0, 0L);
  32.  
  33.        //
  34.        // Add the new line
  35.        //
  36.        if ( pVLBox->wFlags & HASSTRINGS) {
  37.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  38.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, pVLBox->nCountInBox-1, pVLBox->vlbStruct.lData);
  39.        }
  40.        else
  41.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  42.  
  43.        pVLBox->lToplIndex++;
  44.        UpdateVLBWindow(pVLBox, &UpdRect);
  45.  
  46.        //
  47.        // Tell Windows not to paint the whole LB
  48.        //
  49.        ValidateRect(pVLBox->hwndList, NULL);
  50.  
  51.        //
  52.        // Scroll the window up
  53.        //
  54.        ScrollWindow(pVLBox->hwndList, 0, (-1)*pVLBox->nchHeight, NULL, NULL);
  55.  
  56.        //
  57.        // Now tell windows the bottom line needs fixing
  58.        //
  59.        SendMessage(pVLBox->hwndList, LB_GETITEMRECT,
  60.                    pVLBox->nLines-1, (LPARAM) (LPRECT) &UpdRect);
  61.  
  62.        InvalidateRect(pVLBox->hwndList, &UpdRect, TRUE);
  63.  
  64.        UpdateWindow(pVLBox->hwndList);
  65.  
  66.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  67.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, pVLBox->nLines-1, 0L);
  68.           SetFocustoLB(pVLBox);
  69.        }
  70.        else if ( nSelected != LB_ERR ) {
  71.           if ( nSelected != 0 ) {
  72.               // Need to move the selection Up 1
  73.               SendMessage(pVLBox->hwndList, LB_SETCURSEL, nSelected-1, 0L);
  74.           }
  75.        }
  76.  
  77.  
  78.        return VLB_OK;
  79.     }
  80.     return VLB_ERR;
  81. }
  82.  
  83. int VLBScrollUpLine( PVLBOX pVLBox)
  84. {
  85.     RECT   UpdRect;
  86.     RECT   ListRect;
  87.     RECT   FAR *lpRect;
  88.     int    nSelected;
  89.  
  90.     if ( pVLBox->wFlags & USEDATAVALUES )
  91.         pVLBox->vlbStruct.lIndex = -1L;
  92.     else
  93.         pVLBox->vlbStruct.lIndex = pVLBox->lToplIndex;
  94.  
  95.     pVLBox->vlbStruct.lpTextPointer = NULL;
  96.     pVLBox->vlbStruct.lData = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, 0, 0L);
  97.     SendMessage(pVLBox->hwndParent, VLB_PREV, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  98.     if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  99.        nSelected = (int)SendMessage(pVLBox->hwndList, LB_GETCURSEL, 0, 0L);
  100.        if ( nSelected == pVLBox->nLines-1 ) {
  101.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WORD)-1, 0L);
  102.           SetFocustoVLB(pVLBox);
  103.        }
  104.  
  105.        //
  106.        // Remove the bottom String
  107.        //
  108.        SendMessage(pVLBox->hwndList, LB_DELETESTRING, pVLBox->nLines-1, 0L);
  109.  
  110.        //
  111.        // Add the new line
  112.        //
  113.        if ( pVLBox->wFlags & HASSTRINGS) {
  114.            SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  115.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  116.        }
  117.        else
  118.            SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  119.  
  120.        pVLBox->lToplIndex--;
  121.        UpdateVLBWindow(pVLBox, &UpdRect);
  122.  
  123.        //
  124.        // Tell Windows not to paint the whole LB
  125.        //
  126.        ValidateRect(pVLBox->hwndList, NULL);
  127.  
  128.        //
  129.        // Check for partial line at bottom...
  130.        // if so clear it
  131.        //
  132.        SendMessage(pVLBox->hwndList, LB_GETITEMRECT,
  133.                    pVLBox->nLines-1, (LPARAM)(LPRECT)&UpdRect);
  134.  
  135.        GetClientRect(pVLBox->hwndList, &ListRect);
  136.        if ( UpdRect.bottom != ListRect.bottom ) {
  137.            ListRect.bottom = UpdRect.top ;
  138.            lpRect = &ListRect;
  139.        }
  140.        else {
  141.            lpRect = NULL;
  142.        }
  143.  
  144.        //
  145.        // Scroll the window down
  146.        //
  147.        ScrollWindow(pVLBox->hwndList, 0, pVLBox->nchHeight, lpRect, NULL);
  148.  
  149.        //
  150.        // Now tell windows the top line needs fixing
  151.        //
  152.        SendMessage(pVLBox->hwndList, LB_GETITEMRECT,
  153.                    0, (LPARAM)(LPRECT)&UpdRect);
  154.        InvalidateRect(pVLBox->hwndList, &UpdRect, TRUE);
  155.        UpdateWindow(pVLBox->hwndList);
  156.  
  157.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  158.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, 0, 0L);
  159.           SetFocustoLB(pVLBox);
  160.        }
  161.        else if ( nSelected != LB_ERR ) {
  162.           if ( nSelected !=  pVLBox->nLines-1) {
  163.               // Need to move the selection Up 1
  164.               SendMessage(pVLBox->hwndList, LB_SETCURSEL, nSelected+1, 0L);
  165.           }
  166.        }
  167.  
  168.  
  169.        return VLB_OK;
  170.     }
  171.     return VLB_ERR;
  172. }
  173.  
  174.  
  175. int VLBScrollDownPage( PVLBOX pVLBox, int nAdjustment)
  176. {
  177.     int nCount;
  178.     int nSelected;
  179.  
  180.     nSelected = (int)SendMessage(pVLBox->hwndList, LB_GETCURSEL, 0, 0L);
  181.     if ( nSelected == LB_ERR )
  182.         nSelected = -10000;
  183.  
  184.     SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WORD)-1, 0L);
  185.     SetFocustoVLB(pVLBox);
  186.  
  187.     for ( nCount = 0; nCount < pVLBox->nLines+nAdjustment; nCount++) {
  188.         if ( pVLBox->wFlags & USEDATAVALUES )
  189.             pVLBox->vlbStruct.lIndex = -1L;
  190.         else
  191.             pVLBox->vlbStruct.lIndex = pVLBox->lToplIndex + pVLBox->nLines - 1L;
  192.  
  193.         pVLBox->vlbStruct.lpTextPointer = NULL;
  194.         pVLBox->vlbStruct.lData = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, pVLBox->nCountInBox-1, 0L);
  195.         SendMessage(pVLBox->hwndParent, VLB_NEXT, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  196.         if (  pVLBox->vlbStruct.nStatus == VLB_OK ) {
  197.  
  198.            if ( nCount == 0 )
  199.               vlbRedrawOff(pVLBox);
  200.  
  201.            SendMessage(pVLBox->hwndList, LB_DELETESTRING, 0, 0L);
  202.  
  203.            if ( pVLBox->wFlags & HASSTRINGS) {
  204.                SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  205.                SendMessage(pVLBox->hwndList, LB_SETITEMDATA, pVLBox->nCountInBox-1, pVLBox->vlbStruct.lData);
  206.            }
  207.            else
  208.                SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  209.  
  210.            if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  211.               nSelected = pVLBox->nLines-1;
  212.            }
  213.            else {
  214.               nSelected--;
  215.            }
  216.  
  217.            pVLBox->lToplIndex++;
  218.  
  219.         }
  220.         else {
  221.             if ( nCount == 0 )
  222.                 return VLB_ERR;
  223.             break;
  224.         }
  225.     }
  226.  
  227.     if ( nSelected >= 0 ) {
  228.        SendMessage(pVLBox->hwndList, LB_SETCURSEL, nSelected, 0L);
  229.        SetFocustoLB(pVLBox);
  230.     }
  231.     else {
  232.        SetFocustoVLB(pVLBox);
  233.        SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WORD)-1, 0L);
  234.     }
  235.  
  236.     UpdateVLBWindow(pVLBox, NULL);
  237.     vlbRedrawOn(pVLBox);
  238.     return VLB_OK;
  239.  
  240. }
  241.  
  242.  
  243. int VLBScrollUpPage( PVLBOX pVLBox, int nAdjustment)
  244. {
  245.     int nCount;
  246.     int nSelected;
  247.  
  248.     nSelected = (int)SendMessage(pVLBox->hwndList, LB_GETCURSEL, 0, 0L);
  249.     if ( nSelected == LB_ERR )
  250.         nSelected = -10000;
  251.  
  252.     SetFocustoVLB(pVLBox);
  253.     SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WORD)-1, 0L);
  254.  
  255.     for ( nCount = 0; nCount < pVLBox->nLines+nAdjustment; nCount++) {
  256.         if ( pVLBox->wFlags & USEDATAVALUES ) {
  257.             pVLBox->vlbStruct.lIndex = -1L;
  258.         }
  259.         else {
  260.             pVLBox->vlbStruct.lIndex = pVLBox->lToplIndex;
  261.         }
  262.  
  263.         pVLBox->vlbStruct.lpTextPointer = NULL;
  264.         pVLBox->vlbStruct.lData = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, 0, 0L);
  265.         SendMessage(pVLBox->hwndParent, VLB_PREV, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  266.         if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  267.            if ( nCount == 0 )
  268.               vlbRedrawOff(pVLBox);
  269.  
  270.            if ( pVLBox->wFlags & HASSTRINGS) {
  271.                SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  272.                SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  273.            }
  274.            else
  275.                SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  276.  
  277.            if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  278.               nSelected = 0;
  279.            }
  280.            else {
  281.               nSelected++;
  282.            }
  283.  
  284.            SendMessage(pVLBox->hwndList, LB_DELETESTRING, pVLBox->nLines, 0L);
  285.  
  286.            pVLBox->lToplIndex--;
  287.         }
  288.         else  {
  289.             if ( nCount == 0 )
  290.                return VLB_ERR;
  291.            break;
  292.         }
  293.     }
  294.  
  295.     if ( nSelected >= 0 && nSelected <= pVLBox->nLines ) {
  296.        SendMessage(pVLBox->hwndList, LB_SETCURSEL, nSelected, 0L);
  297.        SetFocustoLB(pVLBox);
  298.     }
  299.     else {
  300.        SetFocustoVLB(pVLBox);
  301.        SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WORD)-1, 0L);
  302.     }
  303.  
  304.     UpdateVLBWindow(pVLBox, NULL);
  305.     vlbRedrawOn(pVLBox);
  306.     return VLB_OK;
  307. }
  308.  
  309.  
  310. void UpdateVLBWindow( PVLBOX pVLBox, LPRECT lpRect)
  311. {
  312.     int   nPos;
  313.  
  314.     if ( pVLBox->lNumLogicalRecs == -1L )
  315.        SetScrollPos(pVLBox->hwndList, SB_VERT, 50, TRUE);
  316.     else {
  317.        if ( pVLBox->lNumLogicalRecs <= pVLBox->nLines ) {
  318.           if ( pVLBox->styleSave & VLBS_DISABLENOSCROLL )
  319.              EnableScrollBar(pVLBox->hwndList, SB_VERT, ESB_DISABLE_BOTH);
  320.           else
  321.              ShowScrollBar(pVLBox->hwndList, SB_VERT, FALSE);
  322.        }
  323.        else {
  324.            if ( pVLBox->styleSave & VLBS_DISABLENOSCROLL )
  325.               EnableScrollBar(pVLBox->hwndList, SB_VERT, ESB_ENABLE_BOTH);
  326.            else
  327.               ShowScrollBar(pVLBox->hwndList, SB_VERT, TRUE);
  328.            if ( pVLBox->lToplIndex >= (pVLBox->lNumLogicalRecs-pVLBox->nLines) ) {
  329.                nPos = 100;
  330.            }
  331.            else if (pVLBox->lToplIndex == 0L) {
  332.                nPos = 0;
  333.            }
  334.            else {
  335.                nPos = (int) ((pVLBox->lToplIndex*100L) / (pVLBox->lNumLogicalRecs-pVLBox->nLines+1));
  336.            }
  337.            SetScrollPos(pVLBox->hwndList, SB_VERT, nPos, TRUE);
  338.        }
  339.  
  340.     }
  341.  
  342. }
  343.  
  344.  
  345.  
  346. int VLBFindPos( PVLBOX pVLBox, int nPos)
  347. {
  348.     pVLBox->vlbStruct.lpTextPointer = NULL;
  349.     pVLBox->vlbStruct.lIndex = (LONG) nPos;
  350.     pVLBox->vlbStruct.lData = (LONG) nPos;
  351.     SendMessage(pVLBox->hwndParent, VLB_FINDPOS, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  352.     if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  353.        SetFocustoVLB(pVLBox);
  354.        vlbRedrawOff(pVLBox);
  355.        SendMessage(pVLBox->hwndList, LB_RESETCONTENT, 0, 0L);
  356.  
  357.        if ( pVLBox->wFlags & HASSTRINGS) {
  358.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  359.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  360.        }
  361.        else
  362.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  363.  
  364.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  365.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, 0, 0L);
  366.           SetFocustoLB(pVLBox);
  367.        }
  368.  
  369.        if ( pVLBox->lNumLogicalRecs == -1L )
  370.           pVLBox->lToplIndex = pVLBox->vlbStruct.lData;
  371.        else if ( pVLBox->wFlags & USEDATAVALUES )
  372.           pVLBox->lToplIndex = (LONG)nPos* (pVLBox->lNumLogicalRecs-pVLBox->nLines+1)/100L;
  373.        else
  374.           pVLBox->lToplIndex = pVLBox->vlbStruct.lIndex;
  375.  
  376.        pVLBox->vlbStruct.lIndex = 0L;
  377.        pVLBox->nCountInBox = 1;
  378.        while ( pVLBox->nCountInBox < pVLBox->nLines ) {
  379.           SendMessage(pVLBox->hwndParent, VLB_NEXT, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  380.           if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  381.              if ( pVLBox->wFlags & HASSTRINGS) {
  382.                  SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  383.                  SendMessage(pVLBox->hwndList, LB_SETITEMDATA, pVLBox->nCountInBox, pVLBox->vlbStruct.lData);
  384.              }
  385.              else
  386.                  SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  387.  
  388.              if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  389.                 SendMessage(pVLBox->hwndList, LB_SETCURSEL, 0, 0L);
  390.                 SetFocustoLB(pVLBox);
  391.              }
  392.  
  393.              pVLBox->nCountInBox++;
  394.           }
  395.           else
  396.             break;
  397.        }
  398.        UpdateVLBWindow(pVLBox, NULL);
  399.        vlbRedrawOn(pVLBox);
  400.        return VLB_OK;
  401.     }
  402.     else
  403.         return VLB_ERR;
  404. }
  405.  
  406.  
  407. int VLBFindPage( PVLBOX pVLBox, LONG lFindRecNum, BOOL bUpdateTop)
  408. {
  409.     int nSelected;
  410.  
  411.     nSelected = -1000;
  412.     pVLBox->vlbStruct.lpTextPointer = NULL;
  413.     pVLBox->vlbStruct.lData = pVLBox->vlbStruct.lIndex = lFindRecNum;
  414.     SendMessage(pVLBox->hwndParent, VLB_FINDITEM, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  415.     if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  416.        SetFocustoVLB(pVLBox);
  417.        vlbRedrawOff(pVLBox);
  418.        SendMessage(pVLBox->hwndList, LB_RESETCONTENT, 0, 0L);
  419.  
  420.        if ( pVLBox->wFlags & HASSTRINGS) {
  421.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  422.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  423.        }
  424.        else
  425.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  426.  
  427.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  428.           nSelected = 0;
  429.        }
  430.  
  431.        if ( bUpdateTop ) {
  432.            if ( pVLBox->lNumLogicalRecs == -1L )
  433.               pVLBox->lToplIndex = pVLBox->vlbStruct.lData;
  434.            else if ( pVLBox->wFlags & USEDATAVALUES )
  435.               pVLBox->lToplIndex = pVLBox->lNumLogicalRecs/2L;
  436.            else
  437.               pVLBox->lToplIndex = pVLBox->vlbStruct.lIndex;
  438.        }
  439.  
  440.        pVLBox->vlbStruct.lIndex = lFindRecNum;
  441.        pVLBox->nCountInBox = 1;
  442.        while ( pVLBox->nCountInBox < pVLBox->nLines ) {
  443.           SendMessage(pVLBox->hwndParent, VLB_NEXT, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  444.           if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  445.              if ( pVLBox->wFlags & HASSTRINGS) {
  446.                  SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  447.                  SendMessage(pVLBox->hwndList, LB_SETITEMDATA, pVLBox->nCountInBox, pVLBox->vlbStruct.lData);
  448.              }
  449.              else
  450.                  SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  451.  
  452.              if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  453.                  nSelected = pVLBox->nCountInBox;
  454.              }
  455.  
  456.              pVLBox->nCountInBox++;
  457.           }
  458.           else
  459.             break;
  460.        }
  461.  
  462.        if ( pVLBox->nCountInBox < pVLBox->nLines ) {
  463.           if ( pVLBox->wFlags & USEDATAVALUES )
  464.               pVLBox->vlbStruct.lIndex = -1L;
  465.           else
  466.               pVLBox->vlbStruct.lIndex = pVLBox->lToplIndex;
  467.           pVLBox->vlbStruct.lpTextPointer = NULL;
  468.           pVLBox->vlbStruct.lData = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, 0, 0L);
  469.           while ( pVLBox->nCountInBox < pVLBox->nLines ) {
  470.              SendMessage(pVLBox->hwndParent, VLB_PREV, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  471.              if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  472.                 if ( pVLBox->wFlags & HASSTRINGS) {
  473.                     SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  474.                     SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  475.                 }
  476.                 else
  477.                     SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  478.  
  479.                 if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  480.                     nSelected = 0;
  481.                 }
  482.                 else {
  483.                     nSelected++;
  484.                 }
  485.  
  486.                 pVLBox->nCountInBox++;
  487.                 if ( pVLBox->lNumLogicalRecs != -1L )
  488.                    pVLBox->lToplIndex--;
  489.              }
  490.              else
  491.                 break;
  492.           }
  493.        }
  494.  
  495.        if ( nSelected >= 0 ) {
  496.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, nSelected, 0L);
  497.           SetFocustoLB(pVLBox);
  498.        }
  499.  
  500.        UpdateVLBWindow(pVLBox, NULL);
  501.        vlbRedrawOn(pVLBox);
  502.        return VLB_OK;
  503.     }
  504.     else
  505.         return VLB_ERR;
  506. }
  507.  
  508.  
  509. void VLBFirstPage( PVLBOX pVLBox)
  510. {
  511.     pVLBox->vlbStruct.lpTextPointer = NULL;
  512.     pVLBox->vlbStruct.lData = pVLBox->vlbStruct.lIndex = 0L;
  513.     SendMessage(pVLBox->hwndParent, VLB_FIRST, 0, (LPARAM)((LPVLBSTRUCT)&(pVLBox->vlbStruct)));
  514.     if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  515.        SetFocustoVLB(pVLBox);
  516.        vlbRedrawOff(pVLBox);
  517.        SendMessage(pVLBox->hwndList, LB_RESETCONTENT, 0, 0L);
  518.  
  519.        if ( pVLBox->wFlags & HASSTRINGS) {
  520.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0,  (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  521.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  522.        }
  523.        else
  524.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0,  (LPARAM) pVLBox->vlbStruct.lData);
  525.  
  526.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  527.            SendMessage(pVLBox->hwndList, LB_SETCURSEL, 0, 0L);
  528.            SetFocustoLB(pVLBox);
  529.        }
  530.  
  531.        if ( pVLBox->lNumLogicalRecs == -1L )
  532.           pVLBox->lToplIndex = pVLBox->vlbStruct.lData;
  533.        else if ( pVLBox->wFlags & USEDATAVALUES )
  534.           pVLBox->lToplIndex = 0L;
  535.        else
  536.           pVLBox->lToplIndex = pVLBox->vlbStruct.lIndex;
  537.  
  538.        pVLBox->vlbStruct.lIndex = 0L;
  539.        pVLBox->nCountInBox = 1;
  540.        while ( pVLBox->nCountInBox < pVLBox->nLines ) {
  541.           SendMessage(pVLBox->hwndParent, VLB_NEXT, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  542.           if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  543.             if ( pVLBox->wFlags & HASSTRINGS) {
  544.                 SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  545.                 SendMessage(pVLBox->hwndList, LB_SETITEMDATA, pVLBox->nCountInBox, pVLBox->vlbStruct.lData);
  546.             }
  547.             else
  548.                 SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  549.  
  550.             if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  551.                SendMessage(pVLBox->hwndList, LB_SETCURSEL, pVLBox->nCountInBox, 0L);
  552.                SetFocustoLB(pVLBox);
  553.             }
  554.  
  555.             pVLBox->vlbStruct.lIndex = (LONG) pVLBox->nCountInBox;
  556.             pVLBox->nCountInBox++;
  557.           }
  558.           else
  559.             break;
  560.        }
  561.     }
  562.     UpdateVLBWindow(pVLBox, NULL);
  563.     vlbRedrawOn(pVLBox);
  564. }
  565.  
  566. void VLBLastPage(PVLBOX pVLBox)
  567. {
  568.     pVLBox->vlbStruct.lpTextPointer = NULL;
  569.     pVLBox->vlbStruct.lData = pVLBox->vlbStruct.lIndex = 0L;
  570.     SendMessage(pVLBox->hwndParent, VLB_LAST, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  571.     if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  572.        SetFocustoVLB(pVLBox);
  573.        vlbRedrawOff(pVLBox);
  574.        SendMessage(pVLBox->hwndList, LB_RESETCONTENT, 0, 0L);
  575.  
  576.        if ( pVLBox->wFlags & HASSTRINGS) {
  577.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  578.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  579.        }
  580.        else
  581.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  582.  
  583.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  584.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, 0, 0L);
  585.           SetFocustoLB(pVLBox);
  586.        }
  587.  
  588.        if ( pVLBox->lNumLogicalRecs == -1L )
  589.           pVLBox->lToplIndex = pVLBox->vlbStruct.lData;
  590.        else if ( pVLBox->wFlags & USEDATAVALUES )
  591.           pVLBox->lToplIndex = pVLBox->lNumLogicalRecs;
  592.        else
  593.           pVLBox->lToplIndex = pVLBox->vlbStruct.lIndex;
  594.  
  595.        pVLBox->nCountInBox = 1;
  596.        while ( pVLBox->nCountInBox < pVLBox->nLines ) {
  597.           SendMessage(pVLBox->hwndParent, VLB_PREV, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  598.           if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  599.              if ( pVLBox->wFlags & HASSTRINGS) {
  600.                  SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  601.                  SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  602.              }
  603.              else
  604.                  SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  605.  
  606.              if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  607.                  SendMessage(pVLBox->hwndList, LB_SETCURSEL, pVLBox->nCountInBox, 0L);
  608.                  SetFocustoLB(pVLBox);
  609.              }
  610.  
  611.              pVLBox->nCountInBox++;
  612.              if ( pVLBox->lNumLogicalRecs != -1L )
  613.                 pVLBox->lToplIndex--;
  614.           }
  615.           else
  616.              break;
  617.        }
  618.  
  619.        UpdateVLBWindow(pVLBox, NULL);
  620.        vlbRedrawOn(pVLBox);
  621.     }
  622. }
  623.  
  624.  
  625. static void SetFocustoLB(PVLBOX pVLBox)
  626. {
  627.    pVLBox->wFlags &= ~PARENTFOCUS;
  628.    if ( pVLBox->wFlags & HASFOCUS ) {
  629.       SetFocus(pVLBox->hwndList);
  630.    }
  631. }
  632.  
  633.  
  634. static void SetFocustoVLB(PVLBOX pVLBox)
  635. {
  636.    pVLBox->wFlags |= PARENTFOCUS;
  637.    if ( pVLBox->wFlags & HASFOCUS ) {
  638.       SetFocus(pVLBox->hwnd);
  639.    }
  640. }
  641.